import 'package:flutter/material.dart';
import 'package:flutter_jl_bluetooth_plugin_example/models/ble_func_model.dart';
import 'package:flutter_jl_bluetooth_plugin_example/widgets/common_widgets.dart';

import 'upgrade_page.dart';



class BleFuncListPage extends StatefulWidget {
  @override
  BleFuncListPageState createState() => new BleFuncListPageState();
}

class BleFuncListPageState extends State<BleFuncListPage> {
  List<BleFuncModel> _funcLists = [];

  void _initData() {
    _funcLists.add(
      BleFuncModel(
        name: "OTA升级",
        desc: "设备固件升级",
        onPressed: () {
          Navigator.push(
            context,
            MaterialPageRoute(builder: (context) {
              return UpgradePage();
            }),
          );
        },
      ),
    );
    setState(() {});
  }

  @override
  void initState() {
    super.initState();

    _initData();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        backgroundColor: Colors.white,
        appBar: AppBar(
          title: Text("功能列表"),
          backgroundColor: Colors.blueAccent, //设置appbar背景颜色
          centerTitle: true, //设置标题是否局中
        ),
        body: ListView.builder(
          itemCount: _funcLists.length,
          itemBuilder: (BuildContext context, int index) {
            return _functionWidget(context, index);
          },
        ),
      ),
    );
  }

  /// 功能widget
  Widget _functionWidget(BuildContext context, int index) {
    BleFuncModel funcModel = _funcLists[index];
    return Container(
      child: Column(
        children: [
          ListTile(
            contentPadding: const EdgeInsets.all(10.0),
            title: Text(
              funcModel.name,
              style: TextStyle(
                fontSize: 20,
                color: Colors.black,
              ),
            ),
            subtitle: Text(
              funcModel.desc,
              style: TextStyle(
                fontSize: 15,
                color: Colors.grey,
              ),
            ),
            onTap: funcModel.onPressed,
          ),
          bottomWidget(),
        ],
      ),
    );
  }
}
